﻿@using System

@page "/Blackjack"

<PageTitle>Blackjack</PageTitle>

<h1>Blackjack</h1>

<a href="https://github.com/dotnet/dotnet-console-games/tree/main/Projects/Blackjack" alt="Go To Readme">
	<img title="Go To Readme" alt="Go To Readme" src="https://raw.githubusercontent.com/dotnet/dotnet-console-games/main/.github/resources/readme-black.svg">
</a>

<div class="console-window text-center my-3" @onkeydown="@Console.OnKeyDown" tabindex="0">
	<div class="d-inline-block bg-dark text-light border p-2 text-start shadow padding-0">
		<pre class="console">
			<code>@Console.State</code>
		</pre>
	</div>
	<div>
		<button class="btn btn-primary" @onclick="() => Console.EnqueueInput(ConsoleKey.UpArrow)   ">↑</button>
		<button class="btn btn-primary" @onclick="() => Console.EnqueueInput(ConsoleKey.DownArrow) ">↓</button>
		<button class="btn btn-primary" @onclick="() => Console.EnqueueInput(ConsoleKey.D1) ">1</button>
		<button class="btn btn-primary" @onclick="() => Console.EnqueueInput(ConsoleKey.D2) ">2</button>
		<button class="btn btn-primary" @onclick="() => Console.EnqueueInput(ConsoleKey.D3) ">3</button>
		<button class="btn btn-primary" @onclick="() => Console.EnqueueInput(ConsoleKey.D4) ">4</button>
		<button class="btn btn-primary" @onclick="() => Console.EnqueueInput(ConsoleKey.Enter)     ">enter</button>
		<button class="btn btn-primary" @onclick="() => Console.EnqueueInput(ConsoleKey.Escape)    ">escape</button>
	</div>
</div>

<div class="alert alert-secondary" role="alert">
	&#9000; Keyboard input is supported if you <strong>click</strong> on the game.
</div>

<div class="alert alert-secondary" role="alert">
	&#8635; You can restart the game by <strong>refreshing</strong> the page.
</div>

@code
{
	Games.Blackjack.Blackjack Game;
	BlazorConsole Console;

	public Blackjack()
	{
		Game = new();
		Console = Game.Console;
		Console.WindowWidth = 74;
		Console.WindowHeight = 62;
		Console.TriggerRefresh = StateHasChanged;
	}

	protected override void OnInitialized() => InvokeAsync(Game.Run);
}
